<template>
  <div class="body_all">
    <div class="ba_top">
      <div>
        <el-input
          v-model="searchList.kw"
          style="width: 15%"
          placeholder="联系人名称/公司名称"
          size="mini"
        ></el-input>
        <el-button
          style="margin-left: 8px"
          type="primary"
          icon="el-icon-search"
          @click="search"
          size="mini"
          >搜索</el-button
        >
        <el-button
          type="refresh"
          icon="el-icon-refresh"
          @click="btnRefresh"
          size="mini"
          >重置</el-button
        >
      </div>
      <div style="margin-top: 8px">
        <el-button type="primary" size="mini" @click="synchronization"
          >同步外部联系人</el-button
        >
      </div>
    </div>
    <div class="ba_main">
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        height="250"
        tooltip-effect="dark"
        style="width: 100%"
        class="ellipsis"
      >
        <el-table-column label="联系人名称" width="230" fixed>
          <template slot-scope="scope">
            <el-row :gutter="20">
              <el-col :span="3" style="display: grid">
                <el-image
                  style="width: 25px; height: 25px; border-radius: 5px"
                  :src="scope.row.avatar"
                  fit="fit"
                  :preview-src-list="showImg(scope.row.avatar)"
                ></el-image
              ></el-col>
              <el-col
                :span="21"
                :title="
                  scope.row.name +
                  (scope.row.external_userid !== '' ? '@微信' : '')
                "
              >
                <span style="display: block">{{
                  scope.row.name !== "" ? scope.row.name : "--"
                }}</span></el-col
              >
            </el-row>
          </template>
        </el-table-column>
        <el-table-column label="性别" width="50">
          <template slot-scope="scope">
            <span v-if="scope.row.gender == '0'">未知</span>
            <span v-else-if="scope.row.gender == '1'">男</span>
            <span v-else-if="scope.row.gender == '2'">女</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人类型" width="200">
          <template slot-scope="scope">
            <span v-if="scope.row.type == '1'">微信用户</span>
            <span v-else-if="scope.row.type == '2'">企业微信用户</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column label="备注名" width="200">
          <template slot-scope="scope">
            <span :title="scope.row.remark">{{ scope.row.remark !== "" ? scope.row.remark : "--" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="公司简称" width="200">
          <template slot-scope="scope">
            <span :title="scope.row.corp_name">{{
              scope.row.corp_name !== "" ? scope.row.corp_name : "--"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="公司名称" width="200">
          <template slot-scope="scope">
            <span :title="scope.row.corp_full_name">{{
              scope.row.corp_full_name !== "" ? scope.row.corp_full_name : "--"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.delete==0">未删除</span>
            <span v-else-if="scope.row.delete==1">已删除</span>
            <span v-else-if="scope.row.delete==2">被删除</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column label="描述">
          <template slot-scope="scope">
            <span :title="scope.row.description">{{
              scope.row.description !== "" ? scope.row.description : "--"
            }}</span>
          </template>
        </el-table-column>
        
      </el-table>
      <div class="footer">
        <span style="margin-right: 10px">共{{ datanumber }}条</span>
        <!-- <span>当前第{{ searchList.page }}页共有{{ tableData.length }}条</span> -->
        <span :class="searchList.page == 1 ? 'ban_btn_no' : ''">
          <i
            class="el-icon-arrow-left operable"
            :class="searchList.page == 1 ? 'pageOff' : 'pageOn'"
            @click="prevPage"
          ></i>
        </span>
        <div style="display: inline; margin: 0 10px">
          <el-input
            :title="searchList.page"
            style="width: 60px"
            v-model="searchList.page"
            @change="sizechange()"
            size="mini"
          ></el-input>
          <span style="margin: 0 5px 0 15px">/</span>
          <span>{{ pagenumber == 0 ? "1" : pagenumber }}</span>
        </div>
        <span :class="seenumber > datanumber ? 'ban_btn_no' : ''">
          <i
            class="el-icon-arrow-right operable"
            :class="seenumber > datanumber ? 'pageOff' : 'pageOn'"
            @click="nextPage"
          ></i>
        </span>
        <span style="margin-left: 10px">每页</span>
        <el-select
          style="width: 70px"
          v-model="searchList.size"
          @change="sizechange()"
          placeholder="请选择"
          size="mini"
        >
          <el-option
            v-for="item in sizennList"
            :key="item.value"
            :label="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
        条
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      // 搜索条件
      sizennList: [{ value: 20 }, { value: 50 }, { value: 100 }],
      searchList: {
        page: 1,
        size: "20",
        kw: "",
      },
      datanumber: "0",
      seenumber: "0",
      pagenumber: "0",
      tableData: [],
    };
  },
  created() {
    this.loading = true;
    this.getData();
  },
  methods: {
    // 大图预览
    showImg(img) {
      let imgArr = [];
      imgArr.push(img);
      return imgArr;
    },
    // 获取列表数据
    getData() {
      this.$cmsapi.getExternalList(this.searchList).then(
        (res) => {
          if (res.code == 0) {
            this.seenumber = this.searchList.size * this.searchList.page;
            this.datanumber = res.count;
            this.pagenumber = Math.ceil(res.count / this.searchList.size);
            this.tableData = res.data;
          } else {
            this.$message.error(res.msg);
          }
          this.loading = false;
        },
        (err) => {
          console.log(err);
        }
      );
    },
    // 最大条数变化
    sizechange() {
      this.loading = true;
      this.getData();
    },
    //上一页
    prevPage() {
      this.loading = true;
      this.searchList.page -= 1;
      this.getData();
    }, // 下一页
    nextPage() {
      this.loading = true;
      this.searchList.page += 1;
      this.getData();
    },
    // 搜索
    search() {
      this.loading = true;
      this.getData();
    },
    // 条件重置
    btnRefresh() {
      this.searchList = this.$options.data().searchList;
      this.loading = true;
      this.getData();
    },
    // 同步外部联系人
    synchronization() {
      this.loading = true;
      this.$cmsapi.getFollowUserList().then(
        (res) => {
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "同步成功",
            });
          } else {
            this.$message.error(res.msg);
          }
          this.getData();
        },
        (err) => {
          console.log(err);
        }
      );
    },
  },
};
</script>
<style scoped>
.el-form {
  width: 90%;
}
/deep/ .el-drawer__header {
  margin-bottom: 20px !important;
}
.edit_btn {
  display: inline-flex;
  align-content: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  word-break: break-all;
}
.edit_btn span {
  margin-left: 5px;
}
/* 详情头部 */
.top_data {
  background-color: #f8f9fa;
  padding: 15px;
  margin: 15px;
  margin-top: 0px;
  border-radius: 10px;
  border: 1px solid #f0f0f4;
}
.t_title {
  display: flex;
  font-weight: bolder;
  margin-bottom: 10px;
}
.t_title img {
  width: 20px;
  margin-right: 10px;
}
.t_content {
  line-height: 20px;
  font-size: 12px;
  color: #7887a0;
}
.t_content div {
  display: inherit;
}
.operation {
  float: right;
  display: flex;
  align-items: center;
  font-size: 12px;
}
.step {
  margin-top: 10px;
  width: 100%;
  box-sizing: border-box;
  /* overflow-x: scroll; */
  overflow-y: hidden;
}
.drawer_pad,
.el-descriptions,
/deep/ .el-step__title {
  font-size: 12px;
}
/deep/ .el-step__main {
  white-space: inherit;
  margin-right: 100px;
}
/* 详情日志 */
.bigDetails {
  margin: 10px 0;
}
.detailsLog {
  width: 100%;
  min-height: 40px;
  padding: 10px;
  color: #9b929b;
  background: #f8f9fa;
}
h6 {
  background: #f8f9fa;
  line-height: 25px;
  padding: 10px;
  margin: 10px 0 !important;
}
/deep/ .el-tabs__header {
  margin: 0;
}
</style>